package com.um.jdy.mp.station.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.um.jdy.common.device.entity.vo.FeeVO;
import com.um.jdy.mp.device.entity.vo.PileItemVO;
import com.um.jdy.mp.station.manager.*;
import com.um.springboot.starter.entity.Page;
import com.um.springboot.starter.orm.controller.BaseController;
import com.um.springboot.starter.orm.entity.Response;
import com.um.springboot.starter.orm.params.ListParams;
import com.um.springboot.starter.orm.params.PageParams;
import com.um.springboot.starter.utils.StringUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


/**
 * 方案管理
 *
 * @author cs
 * 日期 2023/5/25
 * 版权所有 广州优匠科技有限公司
 */
@Api(tags = "方案管理")
@Validated
@RestController
@RequestMapping("/api/v1/cms/fee")
@SaCheckLogin
public class FeeController extends BaseController<FeeManager> {

    /**
     * 列表
     * @param name
     * @param type
     * @return
     */
    @ApiOperation("列表")
    @GetMapping({"list"})
    public Response<List<FeeVO>> list(@ApiParam(value = "方案名称") String name,
                                      @ApiParam(value = "方案类型") String type) {
        ListParams params = new ListParams();
        if(!StringUtil.isEmpty(name)){
            params.getCondition().put("s.name", StringUtil.getQueryParam(name));
        }
        if(!StringUtil.isEmpty(type)){
            params.getCondition().put("s.device_type", type);
        }
        return manager.list(params);
    }

    /**
     * 分页列表
     * @param page_no
     * @param page_size
     * @param name
     * @param type
     * @return
     */
    @ApiOperation(value = "分页列表")
    @GetMapping("page")
    public Response<Page<FeeVO>> page(@ApiParam(value = "页码") @NotNull Integer page_no,
                                         @ApiParam(value = "数据量") @NotNull Integer page_size,
                                         @ApiParam(value = "方案名称") String name,
                                         @ApiParam(value = "方案类型") String type) {
        PageParams params = new PageParams();
        params.setPageNo(page_no);
        params.setPageSize(page_size);
        if(!StringUtil.isEmpty(name)){
            params.getCondition().put("s.name", StringUtil.getQueryParam(name));
        }
        if(!StringUtil.isEmpty(type)){
            params.getCondition().put("s.device_type", type);
        }
        params.getCondition().put("orderby", "create_time DESC");
        return manager.page(params);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping({"{id}"})
    public Response<Object> delete(@PathVariable String id) {
        return manager.delete(id);
    }

}
